//
//  Product ListTableViewController.m
//  demo
//
//  Created by maxine on 2016/11/11.
//  Copyright © 2016年 maxine. All rights reserved.
//

#import "ProductListTableViewController.h"
#import "ProductListTableViewCell.h"
#import "MyAppointTableViewController.h"
#import "ProduModel.h"

@interface ProductListTableViewController ()

@property(nonatomic,strong)NSMutableArray *dataArr;

@end

@implementation ProductListTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"产品列表";
    self.tableView.rowHeight = 178;
    
    
    [self getData];

}


/**
 获取数据
 */
- (void)getData{
    //小额贷款登录
    [[ZXHTTPManager sharedManagerNOCer]smallDKloginWithCompleted:^(NSDictionary *jsonDict, NSError *error) {
        if (error) {
            NSLog(@"error = %@",error);
            HUDNormal(@"请检查您的网络");
            return ;
        }
        NSLog(@"jsonDict = %@",jsonDict[@"sessionId"]);
        [[NSUserDefaults standardUserDefaults]setValue:jsonDict[@"sessionId"] forKey:@"sessionId_key"];
        
        //获取小额贷款列表数据
        [[ZXHTTPManager sharedManagerNOCer]sdpordListWithCompleted:^(NSDictionary *jsonDict, NSError *error) {
            if (error) {
                NSLog(@"error = %@",error);
                HUDNormal(@"请检查您的网络");
                return ;
            }
            NSLog(@"jsonDict = %@",jsonDict);
            //此处解析数据然后刷新列表
            if ([jsonDict[@"statusCode"] isEqualToString:@"SUCCESS"]) {
                
                self.dataArr = [ProduModel mj_objectArrayWithKeyValuesArray:jsonDict[@"prods"]];

                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.tableView reloadData];
                });
                
            }
        }];
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ProductListTableViewCell *cell = [ProductListTableViewCell cellWithTableView:tableView];
    cell.promodel = self.dataArr[indexPath.row];
    WeakSelf(Wself);
    cell.pushBlock = ^(){
        ProduModel *model = self.dataArr[indexPath.row];
        MyAppointTableViewController *maVc = [[MyAppointTableViewController alloc]init];
        maVc.model = model;
        [Wself.navigationController pushViewController:maVc animated:YES];
    };
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    

}

@end
